/**
 * Created by 帅熠 on 2016/10/22.
 */
(function ($) {
    $.fn.extend({
        "slide": function (title,body) {
            for (var i = 0; i < title.length; i++) {
                title[i].index = i;
                title[i].onclick = function () {
                    tab(this.index);
                }
            }
            function tab(nowindex) {
                for (var j = 0; j < title.length; j++) {
                    if (nowindex == j) {
                        title[j].style.color = 'blue';
                        body[j].style.display = 'block';
                    } else {
                        title[j].style.color = '';
                        body[j].style.display = 'none';
                    }
                }
            }
            function pre() {
                for (var i = 0; i < body.length; i++) {
                    if (body[i].style.display == 'block') {
                        var now = i;
                        console.log(now);
                    }
                }
                if (now == 0) {
                    now = 4;
                    for (var k = 0; k < body.length; k++) {
                        if (now == k) {
                            title[k].style.color = 'blue';
                            body[k].style.display = 'block';
                        } else {
                            title[k].style.color = '';
                            body[k].style.display = 'none';
                        }
                    }
                } else {
                    now -= 1;
                    for (var k = 0; k < body.length; k++) {
                        if (now == k) {
                            title[k].style.color = 'blue';
                            body[k].style.display = 'block';
                        } else {
                            title[k].style.color = '';
                            body[k].style.display = 'none';
                        }
                    }
                }
            }
            function next() {
                for (var i = 0; i < body.length; i++) {
                    if (body[i].style.display == 'block') {
                        var now = i;
                        console.log(now);
                    }
                }
                if (now == 4) {
                    now = 0;
                    for (var k = 0; k < body.length; k++) {
                        if (now == k) {
                            title[k].style.color = 'blue';
                            body[k].style.display = 'block';
                        } else {
                            title[k].style.color = '';
                            body[k].style.display = 'none';
                        }
                    }
                } else {
                    now += 1;
                    for (var k = 0; k < body.length; k++) {
                        if (now == k) {
                            title[k].style.color = 'blue';
                            body[k].style.display = 'block';
                        } else {
                            title[k].style.color = '';
                            body[k].style.display = 'none';
                        }
                    }
                }
            }
            setInterval(next,2000);
        }
    });
})(jQuery);
